//---------------------------------------------------------------------------
#ifndef CAdressePanelH
#define CAdressePanelH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include "CEdit.h"
#include "CComboBx.h"
#include "CtrlStd.h"

enum eComplementNoVoie
{
  ecnv_RIEN = 0,
  ecnv_BIS,
  ecnv_TER,
  ecnv_QUATER,

  ecnv_TAILLE,
  ecnv_FIRST = ecnv_RIEN,
  ecnv_LAST = ecnv_TAILLE - 1,
};
extern PACKAGE_CTRLSTD const char *lstTypeBis[ecnv_TAILLE]; //Utilisé par CarnAdr.dll

//---------------------------------------------------------------------------
//                              FORMATS D'ADRESSE
//---------------------------------------------------------------------------
#define NB_CAR_NUM           6
#define NB_CAR_BIS           7
#define NB_CAR_TYPE_VOIE    16
#define NB_CAR_LIBELLE_VOIE 51
#define NB_CAR_BAT           8
#define NB_CAR_ESC           8
#define NB_CAR_ETG           4
#define NB_CAR_LOT           8
#define NB_CAR_LIEU_DIT     51
#define NB_CAR_COMPL        51
#define NB_CAR_BP           11
#define NB_CAR_CP            6
#define NB_CAR_VILLE        51
#define NB_CAR_CEDEX        16

class PACKAGE_CTRLSTD TAdresseDetaillee
   {
   public:
      char szNumero[NB_CAR_NUM];
      char szBis[NB_CAR_BIS];     //Bis, Ter, Quad ...
      char szTypeVoie[NB_CAR_TYPE_VOIE];       //Rue, Allée ...
      char szLibelleVoie[NB_CAR_LIBELLE_VOIE];    // des champs Elysées
      char szBatiment[NB_CAR_BAT];
      char szEscalier[NB_CAR_ESC];
      char szEtage[NB_CAR_ETG];
      char szNumLot[NB_CAR_LOT];
      char szLieuDit[NB_CAR_LIEU_DIT];
      char szComplement[NB_CAR_COMPL];
      char szBoitePostale[NB_CAR_BP];
      char szCodePostal[NB_CAR_CP];
      char szVille[NB_CAR_VILLE];
      char szCedex[NB_CAR_CEDEX];
      short int nPays;

      __fastcall TAdresseDetaillee();
      void __fastcall operator=(const TAdresseDetaillee &Classe);
   };

class PACKAGE_CTRLSTD TAdresseFormat1
   {
   public:
      AnsiString aAdresseLigne1;    //Lieu-dit
      AnsiString aAdresseLigne2;    //Rue
      AnsiString aAdresseLigne3;    //Complément d'adresse
      AnsiString aCodePostal;
      AnsiString aVille; //Peut inclure le CEDEX

      __fastcall TAdresseFormat1();
      void __fastcall operator=(const TAdresseFormat1 &Classe);
   };

class PACKAGE_CTRLSTD TAdresseFormat2
   {
   public:
       AnsiString aLieuDit;
       AnsiString aNum;
       AnsiString aNature;
       AnsiString aNomVoie;
       AnsiString aComplement;
       AnsiString aCodePostal;
       AnsiString aVille; //Peut inclure le CEDEX
       __fastcall TAdresseFormat2();
       void __fastcall operator=(const TAdresseFormat2 &Classe);
   };

class PACKAGE_CTRLSTD TAdresseFormat3
   {
   public:
      AnsiString aResidence;
      AnsiString aBatiment;
      AnsiString aEscalier;
      AnsiString aEtage;
      AnsiString aNumLot;
      AnsiString aAdresse;
      AnsiString aCodePostal;
      AnsiString aVille; //Peut inclure le CEDEX

      __fastcall TAdresseFormat3();
      void __fastcall operator=(const TAdresseFormat3 &Classe);
   };

class PACKAGE_CTRLSTD TAdresseFormat4
   {
   public:
      AnsiString aLieuDit;
      AnsiString aNum;
      AnsiString aNature;
      AnsiString aNomVoie;
      AnsiString aBP;
      AnsiString aComplement;
      AnsiString aCodePostal;
      AnsiString aVille; //Peut inclure le CEDEX

      __fastcall TAdresseFormat4();
      void __fastcall operator=(const TAdresseFormat4 &Classe);
   };

//Format d'adresse au norme TDFC
class PACKAGE_CTRLSTD TAdresseFormatTDFC
   {
   public:
      AnsiString     aLieuDit;
      AnsiString     aComplement;
      AnsiString     aNum;
      AnsiString     aNature;
      AnsiString     aNomVoie;
      AnsiString     aBP;
      AnsiString     aCodePostal;
      AnsiString     aVille; //Peut inclure le CEDEX
      short          iIndexPays;

      __fastcall TAdresseFormatTDFC();
      void __fastcall operator=(const TAdresseFormatTDFC &Classe);
   };

//---------------------------------------------------------------------------
//               ENUM POUR LE CHOIX DU FORMAT DU "CAdressePanel"
//---------------------------------------------------------------------------
typedef enum
{
  #define FORMAT_NON_DEFINI (TYPE_FORMAT) -2
  #define FORMAT_DETAILLE   (TYPE_FORMAT) -1 //Réservé aux cas de hautes nécéssités
  FORMAT_1 = 0,
  FORMAT_2,
  FORMAT_3,
  FORMAT_4,
  FORMAT_TDFC
} TYPE_FORMAT;

//---------------------------------------------------------------------------
//                            CLASSE "CCodePostal"
//---------------------------------------------------------------------------
class CCodePostal : public CEdit
{
  private:
    bool m_bCPInternational;
    void __fastcall SetCPInternational(bool bCPInternational);

  protected:
    DYNAMIC void __fastcall DoExit(void);

  __published:
    __property bool CPInternational = { read = m_bCPInternational,  write = SetCPInternational, default = false};

  public:
    __fastcall CCodePostal(TComponent* Owner);
};

//------------------------------------------------------------------------------
//                    CLASSE "CAdressePanel"
//------------------------------------------------------------------------------
class PACKAGE_CTRLSTD CAdressePanel : public TCustomPanel
{
  private:
    CEdit         *Edit1;
    CEdit         *Edit2;
    CEdit         *Edit3;
    CEdit         *Edit4;
    CEdit         *Edit5;
    CEdit         *Edit6;
    CEdit         *Edit7;
    CEdit         *Edit8;

    TLabel        *Label1;
    TLabel        *Label2;
    TLabel        *Label3;
    TLabel        *Label4;
    TLabel        *Label5;
    TLabel        *Label6;
    TLabel        *Label7;
    TLabel        *Label8;
    TLabel        *Label9;

    CCodePostal   *eCP;

    CComboBox     *cbBis;
    CComboBox     *cbPays;

    bool          m_bAfficheLibelle;
    bool          m_bFormatTDFCacPays;
    bool          m_bReadOnly;
    bool          m_bEnabled;
    int           nTailleLabel;   //Taille du label le plus long
    TYPE_FORMAT   m_nFormat;

  private :
    void __fastcall InitTabPays(void);
    void __fastcall SetAfficheLibelle( bool b );
    void __fastcall SetFormatTDFCacPays( bool b );
    void __fastcall SetReadOnly( bool b );
    void __fastcall SetEnabled( bool b );    
    void __fastcall SetTypeFormat( TYPE_FORMAT f );
    void __fastcall cbPaysChange(TObject *Sender);
    void __fastcall MyResize(TObject *Sender);
    void __fastcall MyCanResize(TObject *Sender, int &NewWidth, int &NewHeight, bool &Resize);
    void __fastcall AffichageFormat1( void );
    void __fastcall AffichageFormat2( void );
    void __fastcall AffichageFormat3( void );
    void __fastcall AffichageFormat4( void );
    void __fastcall AffichageFormatTDFC( void );
    void __fastcall Affichage( void );
    void __fastcall SuppressionEdit( void );
    void __fastcall CreationCbPays(void);
    void __fastcall CreationEdit(int NbEdit);
    void __fastcall SuppressionLabel( void );
    unsigned short __fastcall GetBord(int Width, int Height) const;
    enum eComplementNoVoie __fastcall AffecterCBBis(const AnsiString &Nature);
    void __fastcall InitTabOrder( void );
    //Vérifie la validité de la saisie
    bool __fastcall GetAdresseValide(void);
    bool __fastcall GetAdresseVide(void);
  public:
    __fastcall CAdressePanel(TComponent* Owner);
    virtual __fastcall ~CAdressePanel();
    void __fastcall Vider(void);
    //Affiche dans le composant l'adresse contenu dans Adr
    void __fastcall RemplirPanel(const TAdresseFormat1 &_sAdr1);
    void __fastcall RemplirPanel(const TAdresseFormat2 &_sAdr2);
    void __fastcall RemplirPanel(const TAdresseFormat3 &_sAdr3);
    void __fastcall RemplirPanel(const TAdresseFormat4 &_sAdr4);
    void __fastcall RemplirPanel(const TAdresseFormatTDFC &_sAdrTDFC);
    //Récupère l'adresse affichée dans le panel
    void __fastcall LirePanel(TAdresseFormat1 *_sAdr1) const;
    void __fastcall LirePanel(TAdresseFormat2 *_sAdr2) const;
    void __fastcall LirePanel(TAdresseFormat3 *_sAdr3) const;
    void __fastcall LirePanel(TAdresseFormat4 *_sAdr4) const;
    void __fastcall LirePanel(TAdresseFormatTDFC *_sAdrTDFC) const;

    static AnsiString __fastcall StrComplementNoVoie(const AnsiString &Nature);

  __property bool AdresseValide = {read = GetAdresseValide};
  __property bool AdresseVide   = {read = GetAdresseVide};
__published:
  __property BevelInner;
  __property BevelOuter;
  __property bool AfficheLabel        = { read = m_bAfficheLibelle, write = SetAfficheLibelle, default = true};
  __property bool FormatTDFC_AvecPays = { read = m_bFormatTDFCacPays, write = SetFormatTDFCacPays, default = true};
  __property TYPE_FORMAT TypeFormat   = { read = m_nFormat, write = SetTypeFormat, default = FORMAT_1 };
  __property Align;
  __property Anchors;
  __property BevelWidth;
  __property BorderStyle;
  __property BorderWidth;
  __property Color;
  __property bool Enabled  = { read = m_bEnabled,  write = SetEnabled,  default = false};
  __property Font;
  __property PopupMenu;
  __property bool ReadOnly = { read = m_bReadOnly, write = SetReadOnly, default = false};
  __property TabOrder;
  __property TabStop;
  __property Tag;
  __property Visible;
};
//---------------------------------------------------------------------------
#endif
